package cn.marinda.totipotentwar.global;

import cn.marinda.totipotentwar.TotipotentWar;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import sun.plugin2.main.server.Plugin;

import java.util.ArrayList;
import java.util.List;

public class ShopGui extends AbstractGui{
    private ShopData data = TotipotentWar.shopData;

    /**
     * 抽象图形用户界面
     *
     */
    public ShopGui() {
        super("积分商城", "§b[积分商城]");
        setInventory(Bukkit.createInventory(null,data.getSize(),getTitle()));
        defaultSetting();
    }


    /**
     * 默认设置
     */
    @Override
    public void defaultSetting() {
        Inventory inv = this.getInventory();
        int index = 9;
        List<ItemStack> itemList = new ArrayList<>();
        //遍历物品ItemStack
        for(int i : data.getSlotMap().keySet()){
            Slot slot = data.getSlotMap().get(i);

            ItemStack shopItemStack = new ItemStack(Material.getMaterial(slot.getMaterial()),1);
            ItemMeta meta = shopItemStack.getItemMeta();
            meta.setLore(slot.getLore());
            meta.setDisplayName(slot.getDisplayName());
            shopItemStack.setItemMeta(meta);
            itemList.add(shopItemStack);
        }
        for(int i = 0;i<itemList.size();i++){
            inv.setItem((index)+(i+1),itemList.get(i));
        }
    }

    /**
     * 开放的库存
     *
     * @param player 球员
     */
    @Override
    public void openInventory(Player player) {
        player.closeInventory();
        player.openInventory(this.getInventory());
    }
}
